package types

type Algorithm string

const (
	AlgorithmDigest      Algorithm = "digest"
	AlgorithmDigestV2    Algorithm = "digest_v2"
	AlgorithmBloomFilter Algorithm = "bloom_filter"
	AlgorithmCommon      Algorithm = "common"
)

type StoreConfig struct {
	JSONStoreConfig *JSONStoreConfig `json:"json" yaml:"json"`
}

type JSONStoreConfig struct {
	WorkDir string `json:"work_dir" yaml:"work_dir"`
}

type DatabaseConfig struct {
	Mysql          *MysqlConfig `json:"mysql" yaml:"mysql"`
	Mongo          *MongoConfig `json:"mongo" yaml:"mongo"`
	InitSQL        []string     `json:"init_sql" yaml:"init_sql"`
	PostMigrateSQL []string     `json:"post_migrate_sql" yaml:"post_migrate_sql"`
}

type Config struct {
	Algorithm         Algorithm       `json:"algorithm" yaml:"algorithm"`
	SourceSchema      *Schema         `json:"source_schema" yaml:"source_schema"`
	TargetSchema      *Schema         `json:"target_schema" yaml:"target_schema"`
	SourceDatabase    *DatabaseConfig `json:"source_database" yaml:"source_database"`
	TargetDatabase    *DatabaseConfig `json:"target_database" yaml:"target_database"`
	Store             *StoreConfig    `json:"store" yaml:"store"`
	ChunkSize         int64           `json:"chunk_size" yaml:"chunk_size"`
	MaxWorkers        int             `json:"max_workers" yaml:"max_workers"`
	ReadBeforeMigrate bool            `json:"read_before_migrate" yaml:"read_before_migrate"`
}

func (c *Config) GetSchema(isSource bool) *Schema {
	if isSource {
		return c.SourceSchema
	}
	return c.TargetSchema
}

func (c *Config) GetDatabaseConfig(isSource bool) *DatabaseConfig {
	if isSource {
		return c.SourceDatabase
	}
	return c.TargetDatabase
}
